<template>
  <el-container class="home-container">
    <!-- 头部区域 -->
    <el-header>
      <div>
        <img src="../assets/image/heima.png" alt="" />
        <span class="head-title">电商平台</span>
      </div>
      <el-button type="info" @click="logout"> 退出 </el-button>
    </el-header>
    <el-container>
      <!-- 侧边栏区域 -->
      <el-aside>
        <el-menu
          background-color="#2b4b6b"
          text-color="#fff"
          active-text-color="#379BFF"
          :unique-opened="true"
          router
        >
          <el-submenu
            :index=" '/' + menu.path"
            v-for="menu in this.menusData"
            :key="menu.id"
          >
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{ menu.authName }}</span>
            </template>
            <el-menu-item
              :index="'/' + menuchild.path"
              v-for="menuchild in menu.children"
              :key="menuchild.id"
            >
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{ menuchild.authName }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 右侧主体区域 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      menusData: [],
    };
  },
  methods: {
    logout() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    getMenus() {
      this.$axios
        .get("/menus")
        .then((response) => {
          const { data: data, status: status } = response;

          if (status !== 200) {
            this.$message.error("获取菜单失败");
            return;
          }
          if (data.meta.status === 200) {
            this.menusData = data.data;
          }
        })
        .catch(function (error) {
          console.log(error);
        });
    },
  },
  created() {
    this.getMenus();
  },
};
</script>
<style lang="less" scoped>
.home-container {
  // background: #2b4b6b;
  height: 100%;
  .el-header {
    background-color: #2b4b6b;
    .head-title {
      font-size: 30px;
      color: #fff;
    }
    display: flex;
    justify-content: space-between;
    align-items: center;
    div {
      display: flex;
      align-items: center;
    }
  }
  .el-aside {
    background-color: #2b4b6b;
  }
  .el-main {
    background-color: #e9edf1;
  }
}
</style>
